<template>

  <div class="app-container" style="font-size:12px">
    <div class="filter-container">
      <el-date-picker v-model="listQuery.date1" style="width:140px;" format="yyyy-MM-dd" type="datetime" placeholder="订单开始日" />
      <el-date-picker v-model="listQuery.date2" style="width:140px" format="yyyy-MM-dd" type="datetime" placeholder="订单结束日" />
      <el-input v-model="listQuery.customer" placeholder="客户姓名" style="width: 100px;margin-top:6px" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.rebackdate" placeholder="还款日" style="width: 100px;margin-top:6px" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-select v-model="listQuery.sex" placeholder="性别" class="filter-item" style="width:100px;margin-top:6px">
        <el-option label="全部" value="10" />
        <el-option label="男" value="1" />
        <el-option label="女" value="0" />
      </el-select>
      <el-select v-model="listQuery.guarantee" placeholder="担保模式" class="filter-item" style="width:110px;margin-top:6px">
        <el-option label="担保模式" value="" />
        <el-option label="有担保" value="1" />
        <el-option label="无担保" value="2" />
      </el-select>
      <el-select v-model="listQuery.city" placeholder="选择城市" filterable class="filter-item" style="width:110px;margin-top:8px" @change="getRegionList">
        <el-option label="选择城市" value="" />
        <el-option
          v-for="item in city"
          :key="item.city"
          :label="item.name"
          :value="item.city"
        />
      </el-select>
      <!-- <el-select v-model="listQuery.quyu" placeholder="选择区域" class="filter-item" style="width:130px">
        <el-option label="选择区域" value="" />
        <el-option
          v-for="item in quyu"
          :key="item.region_id"
          :label="item.name"
          :value="item.region_id"
        />
      </el-select> -->
      <el-select v-model="listQuery.merchant_type" placeholder="商户类型" filterable class="filter-item" style="width: 130px;">
        <el-option label="商户类型" value="" />
        <el-option value="1" label="医美"/>
        <el-option value="2" label="生美"/>
      </el-select>
      <el-select v-model="listQuery.merchant" placeholder="选择商户" filterable class="filter-item" style="width:110px;margin-top:6px">
        <el-option label="选择商户" value="" />
        <el-option
          v-for="item in merchant_list"
          :key="item.merchant_id"
          :label="item.merchant_name"
          :value="item.merchant_id"
        />
      </el-select>
      <el-select v-model="listQuery.sale_id" placeholder="选择销售" filterable class="filter-item" style="width:110px;margin-top:6px">
        <el-option label="选择销售" value="" />
        <el-option
          v-for="item in sale_list"
          :key="item.sale_id"
          :label="item.real_name"
          :value="item.sale_id"
        />
      </el-select>
      <el-select v-model="listQuery.investor_id" placeholder="选择资方" filterable class="filter-item" style="width:110px;margin-top:6px">
        <el-option label="选择资方" value="" />
        <el-option
          v-for="item in investor"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select>

      <el-select v-model="listQuery.b_model" placeholder="保理模式" class="filter-item" style="width:110px;margin-top:6px">
        <el-option label="保理模式" value="" />
        <el-option label="正常" value="1" />
        <el-option label="买断" value="2" />
        <el-option label="绿通" value="3" />
      </el-select>
      <el-select v-model="listQuery.order_status" placeholder="订单状态" class="filter-item" style="width:110px;margin-top:6px">
        <el-option label="订单状态" value="" />
        <el-option label="还款中" value="1" />
        <el-option label="已完成" value="2" />
        <el-option label="已退单" value="3" />
        <!-- <el-option label="已逾期" value="4" /> -->
        <el-option label="已回购" value="5" />
      </el-select>

      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-top:6px" @click="handleFilter">查询</el-button>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-top:8px" @click="excelout">导出</el-button>
      <!-- <excel /> -->
    </div>

    <el-row style="margin-top:20px;font-size:14px;color:#666">
      <el-col :span="3">订单数量：{{ allcount.all_count }}</el-col>
      <el-col :span="3">项目金额：{{ allcount.allmoney }}</el-col>
      <el-col :span="3">债权金额：{{ allcount.all_amount_money }}</el-col>
      <el-col :span="3">退单费：{{ allcount.all_return }}</el-col>
      <el-col :span="3">打款金额：{{ allcount.all_merchant_money }}</el-col>
      <el-col :span="3">服务费：{{ allcount.all_server_money }}</el-col>
      <el-col :span="3">已还金额：{{ allcount.all_payed_money }}</el-col>

    </el-row>

    <el-table :key="tableKey" v-loading="listLoading" :element-loading-text="loadingtext" :data="list" size="mini" :row-class-name="tableRowClassName" border fit highlight-current-row style="width: 100%;margin-top:20px">
      <el-table-column label="操作" align="center" width="100" class-name="small-padding fixed-width">
        <template slot-scope="{row,$index}">
          <el-dropdown :hide-on-click="false">
            <span class="el-dropdown-link" style="color:#67C23A">
              更多操作
              <i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <!-- <el-dropdown-item>
                <el-button type="primary" size="mini" @click="toPayment(row.order_id)">
                  查看详情
                </el-button>
              </el-dropdown-item> -->
              <el-dropdown-item>
                <el-button v-if="row.order_status!=14&&row.status!=3" type="danger" size="mini" @click="returnOrder(row.order_id)">
                  订单退单
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button type="warning" size="mini" @click="serverMoney(row.order_id,row)">
                  录服务费
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button  type="success" size="mini" @click="channelChoose(row.order_id)">
                  打款账户
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button  type="primary" v-if="row.haier_paytuition_status==0&&row.haier_income_status==1&&row.investor_id==2" size="mini" @click="payTuition(row.order_id)">
                  云贷请款
                </el-button>
              </el-dropdown-item>
              <!-- <el-dropdown-item>
                <el-button  type="warning" v-if="row.invest_status=='1080'" size="mini" @click="toHaierPayment(row.order_id)">
                  云贷计划
                </el-button>
              </el-dropdown-item> -->
              <el-dropdown-item>
                <el-button  type="default" size="mini" @click="description(row.order_id,row)">
                  备注信息
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button v-if="row.order_status!=14" type="danger" size="mini" @click="flag(row.order_id,row)">
                  特殊标记
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button  type="primary" v-if="row.status!=5&&(row.investor_id==2||row.investor_id==3)" size="mini" @click="buyBack(row.order_id,row)">
                  订单回购
                </el-button>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
      <el-table-column label="进件时间" align="center" width="100px">
        <template slot-scope="{row}">
          <!-- {{ row.create_time|formatDate}} -->
          {{ row.create_time }}
        </template>
      </el-table-column>
      <el-table-column label="资方" align="center" width="100px">
        <template slot-scope="{row}">
          <!-- {{ row.create_time|formatDate}} -->
          <span v-if="row.investor_id!=1" style="color:#66cccc;">{{ row.investor_name }}</span>
          <span v-else>{{ row.investor_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="资方状态" align="center" width="100px">
        <template slot-scope="{row}">
          <!-- {{ row.create_time|formatDate}} -->
          {{ row.invest_status_name }}
        </template>
      </el-table-column>
      <el-table-column label="放款时间" align="center" width="100px">
        <template slot-scope="{row}">
          <span>{{ row.paid_date }}</span>
        </template>
      </el-table-column>
      <el-table-column label="省份" align="center">
        <template slot-scope="{row}">
          <span>{{ row.province }}</span>
        </template>
      </el-table-column>
      <el-table-column label="城市" align="center">
        <template slot-scope="{row}">
          <span>{{ row.city }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="区域" align="center">
        <template slot-scope="{row}">
          <span>{{ row.quyu }}</span>
        </template>
      </el-table-column> -->

      <el-table-column label="商户名称" align="center" width="180px">
        <template slot-scope="{row}">
          <span>{{ row.sort_name }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="商户等级" align="center">
        <template slot-scope="{row}">
          <span>{{ row.level_name }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="客户名称" align="center">
        <template slot-scope="{row}">
          <span style="color:dodgerblue;cursor: pointer" @click="toPayment(row.order_id)">{{ row.real_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="担保" align="center" width="70">
        <template slot-scope="{row}">
          <span v-if="row.guarantee!=null">{{ row.guarantee }}</span>
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" width="45">
        <template slot-scope="{row}">
          <span >{{row.sex}}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户电话" align="center" width="120px">
        <template slot-scope="{row}">
          <span>{{ row.mobile }}</span>
        </template>
      </el-table-column>
      <el-table-column label="保理模式" align="center">
        <template slot-scope="{row}">
          <span>{{ row.model_name }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="签约比例" align="center" width="150px">
        <template slot-scope="{row}">
          <span>{{ row.pay_rate }}</span>
        </template>
      </el-table-column> -->

      <el-table-column label="项目金额" align="center">
        <template slot-scope="{row}">
          <span>{{ row.total_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="债权金额" align="center">
        <template slot-scope="{row}">
          <span>{{ row.amount_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际打款比例" align="center" width="120px">
        <template slot-scope="{row}">
          <span>{{ row.factoring_rate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际打款金额" align="center" width="110px">
        <template slot-scope="{row}">
          <span>{{ row.merchant_actual_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="分期数" align="center" width="70px">
        <template slot-scope="{row}">
          <span>{{ row.total_period }}</span>
        </template>
      </el-table-column>
      <el-table-column label="还款日期" align="center">
        <template slot-scope="{row}">
          <span>{{ row.day }}</span>
        </template>
      </el-table-column>
      <el-table-column label="月还款额" align="center">
        <template slot-scope="{row}">
          <span>{{ row.everymonth_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="剩余期数" align="center">
        <template slot-scope="{row}">
          <span>{{ row.no_payed_num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="债权利率" align="center">
        <template slot-scope="{row}">
          <span>{{ row.money_rate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总居间服务费" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.allrate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="首付居间服务费" align="center" width="130px">
        <template slot-scope="{row}">
          <span>{{ row.first_mediate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已付居间服务费" align="center" width="130px">
        <template slot-scope="{row}">
          <span>{{ row.payed_rate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="每期居间服务费" align="center" width="130px">
        <template slot-scope="{row}">
          <span>{{ row.everymonth_rate }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="服务费" align="center">
        <template slot-scope="{row}">
          <span>{{ row.server }}</span>
        </template>
      </el-table-column> -->

      <el-table-column label="应还期数" align="center">
        <template slot-scope="{row}">
          <span>{{ row.should_num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已还期数" align="center">
        <template slot-scope="{row}">
          <span>{{ row.payed_num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已还金额" align="center">
        <template slot-scope="{row}">
          <span>{{ row.paid_money }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="已还本金" align="center">
        <template slot-scope="{row}">
          <span>{{ row.paid_benjin }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="已结算" align="center">
        <template slot-scope="{row}">
          <span>{{ row.settle_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="剩余金额" align="center">
        <template slot-scope="{row}">
          <span>{{ row.no_paid_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="一次性结清" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.onetime_pay }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退单时间" align="center" width="100">
        <template slot-scope="{row}">
          <span >{{ row.refund_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退单备注" align="center" width="100">
        <template slot-scope="{row}">
          <span >{{ row.refund_desc }}</span>
        </template>
      </el-table-column>
      <el-table-column label="违约金" align="center">
        <template slot-scope="{row}">
          <span>{{ row.chargeback }}</span>
        </template>
      </el-table-column>
      <el-table-column label="逾期数" align="center">
        <template slot-scope="{row}">
          <span>{{ row.late_num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="逾期期数" align="center">
        <template slot-scope="{row}">
          <span>{{ row.late_num_m }}</span>
        </template>
      </el-table-column>
      <el-table-column label="逾期金额" align="center">
        <template slot-scope="{row}">
          <span>{{ row.late_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="滞纳金" align="center">
        <template slot-scope="{row}">
          <span>{{ row.late_fee }}</span>
        </template>
      </el-table-column>
      <el-table-column label="办单费" align="center">
        <template slot-scope="{row}">
          <span>{{ row.server }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" width="150px">
        <template slot-scope="{row}">
          <span>{{ row.project }}</span>
        </template>
      </el-table-column>
      <el-table-column label="签单人" align="center">
        <template slot-scope="{row}">
          <span>{{ row.sale_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" width="110">
        <template slot-scope="{row}">
          <span>{{ row.admin_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="打款账户" align="center" width="110">
        <template slot-scope="{row}">
          <span>{{ row.channel_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="当前状态" align="center">
        <template slot-scope="{row}">
          <span>{{ row.status_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结清时间" align="center" width="100">
        <template slot-scope="{row}">
          <span>{{ row.completed_date }}</span>
        </template>
      </el-table-column>
      <el-table-column label="催收人" align="center">
        <template slot-scope="{row}">
          <span>{{ row.sname }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注信息" align="center" width="200">
        <template slot-scope="{row}">
          <span>{{ row.desc }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="结算渠道姓名" align="center">
        <template slot-scope="{row}">
          <span>{{ row.channel_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否打款" align="center">
        <template slot-scope="{row}">
          <span v-if="row.is_hold">不打款</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="操作" align="center" width="300" class-name="small-padding fixed-width">
        <template slot-scope="{row,$index}">
          <el-button type="primary" size="mini" @click="toPayment(row.order_id)">
            查看详情
          </el-button>
          <el-button v-if="row.order_status!=14&&row.status!=3" type="danger" size="mini" @click="returnOrder(row.order_id)">
            退单
          </el-button>
          <el-button  type="primary" size="mini" @click="serverMoney(row.order_id)">
            服务费
          </el-button>
        </template>
      </el-table-column> -->
      
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

    <el-dialog title="退单" :visible.sync="returnOrderAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="form" label-width="120px">
        <el-form-item label="退单费">
          <el-input v-model="form.chargeback" />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.desc" />
        </el-form-item>
        <el-form-item label="退单时间">
          <div class="block">
            <el-date-picker
              v-model="form.refund_time"
              format="yyyy-MM-dd"
              type="datetime"
              placeholder="选择日期"
            />
          </div>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="returnOrderSubmit()">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="服务费" :visible.sync="serverAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="form" label-width="120px">
        <el-form-item label="金额">
          <el-input v-model="form.serverMoneyNun" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="serverMoneySubmit()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="回购" :visible.sync="buyBackAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="form" label-width="120px">
        <el-form-item label="回购金额">
          <el-input v-model="form.buy_back_money"  type="number" />
        </el-form-item>
        <el-form-item label="回购本金">
          <el-input v-model="form.buy_back_benjin"  type="number" />
        </el-form-item>
        <el-form-item label="已还资方期数">
          <el-input v-model="form.paid_num" type="number" />
        </el-form-item>
        <el-form-item label="回购时间">
          <div class="block">
            <el-date-picker
              v-model="form.buy_back_time"
              format="yyyy-MM-dd"
              type="datetime"
              placeholder="选择日期"
            />
          </div>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="buyBackSubmit()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="特殊标记" :visible.sync="flagAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="form" label-width="120px">
        <el-form-item label="特殊标记">
          <el-checkbox-group v-model="form.flag">
            <el-checkbox label="2" >特批</el-checkbox>
            <el-checkbox label="10" >其他</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="flagSubmit()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="channelChooseAble" title="打款账户" style="width:1500px">
      <template>
        <el-transfer
          v-model="choose"
          filterable
          filter-placeholder="请输入收款人"
          :titles="title"
          target-order="unshift"
          :data="channelList"
        />
      </template>
      <span slot="footer" class="dialog-footer">
        <el-button @click="channelChooseAble = false">
          取消
        </el-button>
        <el-button type="primary" @click="submmitChannel()">
          确定
        </el-button>
      </span>
    </el-dialog>
    <el-dialog title="备注信息" :visible.sync="descriptionAble" style="width:1000px;margin:auto">
      <el-form ref="dataForm" :model="descform" label-width="120px">
        <el-form-item label="备注信息">
          <el-input v-model="descform.desc" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="descSubmit()">确 定</el-button>
      </span>
    </el-dialog>

  </div>

</template>

<script>
import excel from '@/components/excelout/index.vue'
import {
  channelBankList, submmitChannel
} from '@/api/channel'
import {
  financeOrderList, getRegion, exceloutfinance, returnOrderSubmit, serverMoneySubmit, backendgetmerchantregion,descSubmit,payTuition,flagSubmit,buyBackSubmit
} from '@/api/finance'
import { formatDate } from '@/utils/formatDate.js'
import { merchantListOnlyMerchant } from '@/api/merchant'
import { fetchList } from '@/api/sale'
import waves from '@/directive/waves' // waves directive
import {
  parseTime
} from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'ComplexTable',
  components: {
    Pagination, excel
  },
  directives: {
    waves
  },
  filters: {
   	formatDate(time) {
   	        time = time * 1000
   	        const date = new Date(time)

   	        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
   	      }
  },
  data() {
    return {
      buyBackAble:false,
      investor:[],
      form: {
        chargeback: '',
        refund_time: '',
        desc:'',
        order_id: '',
        serverMoneyNun: '',
        flag:[],
        buy_back_money:'',
        paid_num:0
      },
      loadingtext:'正在加载数据...',
      descform: {
        order_id:'',
        desc:''
      },
      tableKey: 0,
      flagAble:false,
      descriptionAble:false,
      returnOrderAble: false,
      channelChooseAble: false,
      serverAble: false,
      title: ['账户列表', '已选列表'],
      tableRecord: 1,
      list: null,
      channelList: [],
      allcount: [],
      record_list: null,
      listRecordLoading: true,
      recordTotal: 0,
      total: 0,
      listLoading: true,
      city: [],
      choose: [],
      quyu: [],
      listQuery: {
        page: 1,
        limit: 10,
        customer: '',
        rebackdate: '',
        month:'',
        city: '',
        quyu: '',
        merchant: '',
        sale_id: '',
        b_model: '',
        order_status: '',
        excel: 0,
        date1: '',
        date2: '',
        sex: '',
        guarantee: ''
      },
      listRecordQuery: {
        page: 1,
        limit: 20,
        order_id: ''
      },
      listMerchantQuery: {
        page: 1,
        limit: 500
      },
      textMap: {
        record: '订单记录',
        create: 'Create'
      },
      merchant_list: [],
      sale_list: [],
      dialogRecordVisible: false,
      dialogStatus: '',
      downloadLoading: false
    }
  },
  created() {
    this.cacheQueryFormat()
    this.getList()
    this.getRegionList()
    this.getMerchantList()
    // this.getSaleList()
    // 添加钩子，页面刷新
    window.addEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  destroyed() {
    // 添加钩子，页面刷新
    window.removeEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  methods: {
    payTuition(order_id){
      this.$confirm(
        '确定要发起请款吗?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        this.listLoading = true;
        this.loadingtext = '正在发起请款，请稍后...',
        payTuition({order_id:order_id}).then(response => {
          if(response.data.code=='0000'){
              this.$notify({
                title: '提示',
                message: '请款成功等待放款',
                type: 'success',
                duration: 2000,
              })
          }else if(response.data.code=='1001'){
            this.$notify({
              title: '提示',
              message: '请补件',
              type: 'error',
              duration: 2000,
            })
          }else{
            this.$notify({
              title: '提示',
              message: '系统错误',
              type: 'error',
              duration: 2000,
            })
          }
          this.getList();
        })
      })
      
    },
    beforeunloadFn(e) {
      // 刷新页面事件
      sessionStorage.removeItem('financeList')
    },
    cacheQueryFormat() {
      const cacheQuery = sessionStorage.getItem('financeList')
      if (cacheQuery) {
        this.listQuery = JSON.parse(cacheQuery)
      }
    },
    getList() {
      sessionStorage.setItem('financeList', JSON.stringify(this.listQuery))
      financeOrderList(this.listQuery).then(response => {
        if (!this.listQuery.excel) {
          this.list = response.data.list.data
          this.total = response.data.list.total
          this.allcount = response.data.countall

          setTimeout(() => {
            this.listLoading = false
          }, 0.1 * 1000)
        } else {
          this.listQuery.excel = 0
        }
      })
    },
    returnOrder(order_id) {
      this.$confirm(
        '确定要退单吗?',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        this.returnOrderAble = true
        this.form.order_id = order_id
      })
    },
    returnOrderSubmit() {
      returnOrderSubmit(this.form).then(response => {
        this.$notify({
          title: '提示',
          message: '修改成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.returnOrderAble = false
      })
    },
    serverMoneySubmit() {
      serverMoneySubmit(this.form).then(response => {
        this.$notify({
          title: '提示',
          message: '添加成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.serverAble = false
      })
    },
    buyBackSubmit() {
      buyBackSubmit(this.form).then(response => {
        this.$notify({
          title: '提示',
          message: '回购添加成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.buyBackAble = false
      })
    },
    descSubmit() {
      descSubmit(this.descform).then(response => {
        this.$notify({
          title: '提示',
          message: '添加成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.descriptionAble = false
      })
    },
    handleFilter() {
      this.listLoading = true
      this.listQuery.page = 1
      this.getList()
    },
    serverMoney(order_id,row) {
      this.form.order_id = order_id
      this.form.serverMoneyNun = row.server
      this.serverAble = true
    },
    buyBack(order_id,row) {
      this.form.order_id = order_id
      this.buyBackAble = true
    },
    flag(order_id,row) {
      this.form.order_id = order_id
      this.form.flag = row.flag
      this.flagAble = true
      console.log(this.form)
    },
    flagSubmit(){
      flagSubmit(this.form).then(response => {
        this.$notify({
          title: '提示',
          message: '标记成功',
          type: 'success',
          duration: 2000,
          onClose: this.getList()
        })
        this.flagAble = false
      })
    },
    description(order_id,row) {
      this.descform.order_id = order_id
      this.descform.desc = row.desc
      this.descriptionAble = true
    },
    excelout() {
      this.listLoading = true
      this.listQuery.page = 1
      this.listQuery.limit = this.total
      exceloutfinance(this.listQuery).then(response => {
        this.listLoading = false
        const filepath = response.data.path
        window.location.href = filepath
      })
    },

    getRegionList() {
      backendgetmerchantregion(this.listQuery).then(response => {
        if (this.listQuery.city) {
          this.quyu = response.data
        } else {
          this.city = response.data
        }
      })
    },
    // getSaleList() {
    //   fetchList().then(response => {
    //     this.sale_list = response.data.list
    //   })
    // },
    getMerchantList() {
      merchantListOnlyMerchant(this.listMerchantQuery).then(response => {
        this.merchant_list = response.data.merchant.data
        this.sale_list = response.data.sale.data
        this.investor = response.data.investor
      })
    },
    getChannelList() {
      channelBankList().then(response => {
        // this.channelList = response.data.list
        this.channelList = []
        const d = response.data.data

        for (let i = 0; i < d.length; i++) {
          // let a = {key:d[i].merchant_id,label:d[i].sort_name,search: d[i].real_name}
          this.channelList.push({ key: d[i].channel_id, label: d[i].bank_person, search: d[i].name })
        }
        console.log(this.channelList)
      })
    },
    channelChoose(order_id) {
      this.form.order_id = order_id
      this.channelChooseAble = true
      this.getChannelList()
    },
    submmitChannel() {
      const data = { order_id: this.form.order_id, channel: this.choose }
      submmitChannel(data).then(response => {
        this.listLoading = true
        if (response.code == 200) {
          this.choose = []
          this.listLoading = false
          this.channelChooseAble = false
          this.$notify({
            title: 'Success',
            message: '完成！',
            type: 'success',
            duration: 2000,
            onClose: this.getList()
          })
        }
      })
    },
    toPayment(order_id) {
      this.$router.push('/finance/customerpayment/' + order_id)
    },
    toHaierPayment(order_id) {
      this.$router.push('/finance/haier_payment/' + order_id)
    },

    handleRecord(order_id) {
      console.log(order_id)
      this.dialogStatus = 'record'
      this.dialogRecordVisible = true
      this.listRecordQuery.order_id = order_id
      fetchOrderRecordListByOrderId(this.listRecordQuery).then(res => {
        this.record_list = res.data.list
        this.recordTotal = res.data.count
        setTimeout(() => {
          this.listRecordLoading = false
        }, 1.0 * 1000)
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.s == 1) {
        return 'success-row'
      } else if (row.s == 2) {
        return 'warning-row'
      } else if (row.s == 3) {
        return 'default-row'
      }
      return ''
    }

  }
}
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
  }
  td{padding: 0;}
  select{
    width:100px;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
    float: left;
  }
   .el-table .warning-row {
      background: orangered;
    }

  .el-table .success-row {
    background: #98dd72;
  }
  .el-table .default-row {
    background: #ccc;
  }
</style>
